package top.lyc829.aircontroller.ui.videoCacheDetail;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;


import java.util.List;

import top.lyc829.aircontroller.R;
import top.lyc829.aircontroller.ui.vidoeDetial.VideoDetailAdapter;
import top.lyc829.aircontroller.ui.videoPlay.VideoPlayActivity;

public class VideoCacheDetailActivity extends Activity {

    private String name;
    private List<String> parts;
    private ListView listView;
    private TextView nameText;
    private VideoDetailAdapter videoDetailAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_cache_detail);
        getInfo();
        init();
    }

    private void init(){
        nameText = findViewById(R.id.name_text);
        nameText.setText(name);
        listView = findViewById(R.id.list_view);
        listView.setOnItemClickListener(adapterListener);
        videoDetailAdapter = new VideoDetailAdapter(this,R.layout.video_detail_item,parts);
        listView.setAdapter(videoDetailAdapter);
    }

    private void getInfo(){
        Intent intent = getIntent();
        name = intent.getStringExtra("name");
        parts = intent.getStringArrayListExtra("parts");
    }

    private AdapterView.OnItemClickListener adapterListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String part = parts.get(position);
            Intent intent = new Intent(getApplicationContext(), VideoPlayActivity.class);
            intent.putExtra("name",name);
            intent.putExtra("part",part);
            startActivity(intent);
        }
    };
}